package com.goodving.guli.view;

import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.activity.ScaleActivity;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.eventbus.EventGoalsUpdated;
import com.goodving.guli.bt.eventbus.EventLoadDataComplete;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdateUnit;
import com.goodving.guli.bt.eventbus.EventWeightTargetUpdated;
import com.goodving.guli.bt.model.Birthday;
import com.goodving.guli.bt.model.C1060e;
import com.goodving.guli.bt.model.C1981P;
import com.goodving.guli.bt.model.DataManager;
import com.goodving.guli.bt.model.HwSyncDataStatus;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.model.WeightInfo;
import com.goodving.guli.bt.model.WeightInfoManager;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.C3843c;
import com.goodving.guli.bt.profile.scale.HwConnStatus;
import com.goodving.guli.bt.profile.scale.ScaleWeightInfo;
import com.goodving.guli.bt.ui.CirclePageIndicator;
import com.goodving.guli.bt.ui.DynamicView;
import com.goodving.guli.bt.ui.PagerFragment;
import com.goodving.guli.bt.utils.WeightUtil;
import com.goodving.guli.bt.weight.UserInfo;
import com.goodving.guli.bt.weight.UserInfoManager;
import com.goodving.guli.bt.weight.family.WeightChooseUserActivity;
import com.goodving.guli.model.DeviceSource;
import com.goodving.guli.model.Keeper;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

import cn.com.smartdevices.bracelet.chart.util.AnimUtil;
import cn.com.smartdevices.bracelet.chart.util.C0800p;
import cn.com.smartdevices.bracelet.chart.util.ChartData;
import cn.com.smartdevices.bracelet.chart.util.DynamicData;
import de.greenrobot.event.EventBus;


/**
 * Created by john on 2015/12/1.
 */
public class DynamicFragment extends Fragment implements C1060e { // ay
    public static final int f9610a = 0;
    public static final int f9611b = 1;
    public static Handler mHandler = null;
    private static final String TAG = "DynamicFragment";
    private static final String f9614e = "weight_overload_fragment";
    private Boolean f9615A;
    private int f9616B;
    private boolean f9617C;
    private boolean f9618D;
    private boolean f9619E;
    private boolean f9620F;
    private C1981P f9621G;
    private C1981P f9622H;
    private int f9623I;
    private int f9624J;
    private boolean f9625K;
    private final int f9626f;
    private final int f9627g;
    private final int f9628h;
    private final int f9629i;
    private final DataManager mDataManager;
    private int f9631k;
    private FragmentManager mFragmentManager;
    private ViewPager mViewPager;
    private PageIndicator mPageIndicator;
    private GuliFragmentPagerAdapter fragmentPagerAdapter; // f9635o
    private TextView mTextView1;
    private int f9637q;
    private int f9638r;
    private int f9639s;
    private int f9640t;
    private int f9641u;
    private String f9642v;
    private String f9643w;
    private ValueAnimator mAnimatorX;
    private ValueAnimator mAnimatorY;
    private int type; // f9646z

    static {
        mHandler = null;
    }


    class GuliFragmentPagerAdapter extends FragmentPagerAdapter {
        final /* synthetic */ DynamicFragment dynamicFragment; // f9476c
        private ArrayList<PagerFragment> fragmentArrayList; // f9477d

        public GuliFragmentPagerAdapter(DynamicFragment ayVar, FragmentManager fragmentManager) {
            super(fragmentManager);
            this.dynamicFragment = ayVar;
            m14264d();
        }

        private void m14256g(int i) {
            Bundle bundle = new Bundle();
            bundle.putInt(ChartData.KEY_MODE, i);
            this.fragmentArrayList.add((PagerFragment) Fragment.instantiate(this.dynamicFragment.getActivity(), PagerFragment.class.getName(), bundle));
        }

        public int m14257a(Object obj) {
            return -2;
        }

        public Fragment getItem(int i) {  //m14258a
            return (Fragment) this.fragmentArrayList.get(i);
        }

        public void m14259a(float f) {
            Iterator it = this.fragmentArrayList.iterator();
            while (it.hasNext()) {
                ((PagerFragment) it.next()).m14271a(f);
            }
        }

        public void m14260a(PageIndicator c1858c) {
            Iterator it = this.fragmentArrayList.iterator();
            while (it.hasNext()) {
                ((PagerFragment) it.next()).m14272a(c1858c);
            }
        }

        public void m14261a(boolean z) {
            Iterator it = this.fragmentArrayList.iterator();
            while (it.hasNext()) {
                ((PagerFragment) it.next()).m14274a(z);
            }
        }

        public int getCount () { // m14262b
            return this.fragmentArrayList.size();
        }

        public void m14263b(boolean z) {
            Iterator it = this.fragmentArrayList.iterator();
            while (it.hasNext()) {
                PagerFragment aGVar = (PagerFragment) it.next();
                aGVar.m14273a(Boolean.valueOf(z));
                if (aGVar.type == PersonInfo.INCOMING_CALL_DISABLE_BIT) {
                    aGVar.m14273a(Boolean.valueOf(false));
                }
            }
        }

        public void m14264d() {
            this.fragmentArrayList = new ArrayList(3);
            if (this.dynamicFragment.f9618D) {
                m14256g(16);
            }
            if (this.dynamicFragment.f9619E) {
                m14256g(1);
            }
            if (this.dynamicFragment.f9620F) {
                m14256g(PersonInfo.INCOMING_CALL_DISABLE_BIT);
            }
        }

        public PagerFragment getPagerFragment(int i) { // m14265e
            Iterator it = this.fragmentArrayList.iterator();
            while (it.hasNext()) {
                PagerFragment aGVar = (PagerFragment) it.next();
                if (aGVar.type == i) {
                    return aGVar;
                }
            }
            return null;
        }

        public DynamicView m14266f(int i) {
            PagerFragment e = getPagerFragment(i);
            return e != null ? e.dynamicView : null;
        }
    }

    public DynamicFragment() {
        this.f9626f = 4114;
        this.f9627g = 4115;
        this.f9628h = 4116;
        this.f9629i = 4117;
        this.mDataManager = DataManager.m12179a();
        this.f9631k = -1;
        this.f9642v = null;
        this.f9643w = null;
        this.type = f9610a;
        this.f9615A = Boolean.valueOf(false);
        this.f9616B = f9610a;
        this.f9617C = false;
        this.f9621G = new C1981P();
        this.f9622H = new C1981P();
        this.f9623I = C3843c.MILI.m25103b();
        this.f9624J = C3843c.MILI.m25103b();
    }

    class aB implements C0800p {
        final /* synthetic */ DynamicFragment f9471a;

        aB(DynamicFragment ayVar) {
            this.f9471a = ayVar;
        }

        public void m8763a(int i) {
            ((ScaleActivity) this.f9471a.getActivity()).applyStatusBarTint(i);
        }
    }

    private ValueAnimator m14417a(int i, int i2) {
        C0800p aBVar = new aB(this);
        View[] viewArr = new View[f9611b];
        viewArr[f9610a] = this.mViewPager;
        return (ValueAnimator) AnimUtil.m8741a(i, i2, aBVar, viewArr);
    }

    public static DynamicFragment m14418a() {
        DynamicFragment ayVar = new DynamicFragment();
        ayVar.setArguments(new Bundle());
        return ayVar;
    }

    private void m14420a(Message message) {
        if (this.f9621G != null) {
            int i = this.f9621G.f11135c;
            int i2 = message.arg1;
            boolean z = message.arg2 == f9611b;
            GuliLog.tracePrintInfo(TAG, "Weight CurrentShownUID " + i + ", Changed : " + i2);
            if (i == i2 || z) {
                m14435c(i2);
                m14432b(true);
            }
        }
    }

    private void m14421a(DynamicData c0802r) {
        GuliLog.tracePrintInfo(TAG, "Update Dynamic Tip!!");
        String str = C3657a.f18328f;
        str = C3657a.f18328f;
        Object[] r3;
        Calendar instance = Calendar.getInstance();
        GuliLog.tracePrintInfo(TAG, "CurrentTime : " + DateFormat.format("yyyy-MM-dd hh:mm:ss", instance));
        Calendar instance2 = Calendar.getInstance();
        long readSyncTime = Keeper.readSyncTime(this.f9623I);
        if (readSyncTime == -1) {
            instance2.add(Calendar.DAY_OF_YEAR, -1);
        } else {
            instance2.setTimeInMillis(readSyncTime);
        }
        GuliLog.tracePrintInfo(TAG, "LastSyncTime : " + DateFormat.format("yyyy-MM-dd hh:mm:ss", instance2));
        str = ((Utils.m8031b(instance2, instance) > 0 || instance2.get(Calendar.HOUR_OF_DAY) < 5) && instance.get(Calendar.HOUR_OF_DAY) >= 5) ? getString(R.string.dynamic_tip_sleep_unsynced) : !c0802r.m8809m() ? getString(R.string.dynamic_tip_unweared) : getString(R.string.dynamic_sleep_tip);
        c0802r.m8784b(str);
        instance2 = Calendar.getInstance();
        readSyncTime = Keeper.readRealtimeStepsTimestamp(this.f9623I);
        if (readSyncTime == -1) {
            instance2.add(Calendar.DAY_OF_YEAR, -1);
        } else {
            instance2.setTimeInMillis(readSyncTime);
        }
        GuliLog.tracePrintInfo(TAG, "LastSyncRealStepTime : " + DateFormat.format("yyyy-MM-dd hh:mm:ss", instance2));
        if (Utils.m8031b(instance2, instance) > 0) {
            str = getString(R.string.dynamic_tip_step_unsynced);
        } else {
            long timeInMillis = (long) ((int) ((instance.getTimeInMillis() - instance2.getTimeInMillis()) / 60000));
            if (timeInMillis < 2) {
                str = getString(R.string.dynamic_step_tip);
            } else if (timeInMillis >= 60) {
                r3 = new Object[f9611b];
                r3[f9610a] = Long.valueOf(timeInMillis / 60);
                str = getString(R.string.dynamic_tip_step_sync_time_hour, r3);
            } else {
                r3 = new Object[f9611b];
                r3[f9610a] = Long.valueOf(timeInMillis);
                str = getString(R.string.dynamic_tip_step_sync_time_min, r3);
            }
        }
        c0802r.m8778a(str);
    }

    private void m14426a(ScaleWeightInfo c3925e, List<UserInfo> list) {
        if (getActivity().getFragmentManager().findFragmentByTag(f9614e) == null && Utils.m8055c(getActivity())) {
            int[] iArr = new int[list.size()];
            for (int i = f9610a; i < list.size(); i += f9611b) {
                iArr[i] = ((UserInfo) list.get(i)).uid;
            }
            Intent intent = new Intent(getActivity(), WeightChooseUserActivity.class);
            intent.putExtra(ScaleWeightInfo.WEIGHTADVDATA_KEY, c3925e.m25503n());
            intent.putExtra("USER_LIST", iArr);
            getActivity().startActivity(intent);
            C0668a.m8126a(getActivity().getApplicationContext(), C0668a.fQ);
        }
    }

    private void m14427a(String str, String str2) {
    }

    private int m14428b(int i, boolean z) {
        if (this.f9618D && this.f9619E && this.f9620F) {
            switch (i) {
                case f9611b /*1*/:
                    this.mViewPager.setCurrentItem((int) f9611b, z);
                    break;
                case C4220a.bp /*16*/:
                    this.mViewPager.setCurrentItem((int) f9610a, z);
                    break;
                case PersonInfo.INCOMING_CALL_DISABLE_BIT /*256*/:
                    this.mViewPager.setCurrentItem(2, z);
                    break;
            }
            ((View) this.mPageIndicator).setAlpha(1);
        } else if (this.f9618D && this.f9619E) {
            switch (i) {
                case f9611b /*1*/:
                    this.mViewPager.setCurrentItem((int) f9611b, z);
                    break;
                case C4220a.bp /*16*/:
                    this.mViewPager.setCurrentItem((int) f9610a, z);
                    break;
                default:
                    i = f9611b;
                    break;
            }
            ((View) this.mPageIndicator).setAlpha(1);
        } else if (this.f9619E && this.f9620F) {
            switch (i) {
                case f9611b /*1*/:
                    this.mViewPager.setCurrentItem((int) f9610a, z);
                    break;
                case PersonInfo.INCOMING_CALL_DISABLE_BIT /*256*/:
                    this.mViewPager.setCurrentItem((int) f9611b, z);
                    break;
                default:
                    i = f9611b;
                    break;
            }
            ((View) this.mPageIndicator).setAlpha(1);
        } else {
            if (this.f9619E) {
                i = f9611b;
            } else if (this.f9620F) {
                i = PersonInfo.INCOMING_CALL_DISABLE_BIT;
            }
            ((View) this.mPageIndicator).setAlpha(0.0f);
        }
        return i;
    }

    private void m14432b(boolean z) {
        boolean z2 = true;
        if (getActivity() != null) {
            DynamicData a = ChartData.m8731a();
            a.m8775a(this.f9631k, this.f9623I);
            a.m8821y();
            if (this.f9620F) {
                int age;
                int i = Keeper.readPersonInfo().miliConfig.weightUnit;
                ScaleWeightInfo c3925e = this.f9621G.weightInfo;
                if (!DeviceSource.hasBindWeight()) {
                    int h = c3925e.m25497h();
                    float j = c3925e.m25499j();
                    c3925e.setUnitType(i);
                    c3925e.m25488b(WeightUtil.m15717c(j, h, i));
                } else if (c3925e.m25497h() != i) {
                    PersonInfo readPersonInfo = Keeper.readPersonInfo();
                    readPersonInfo.miliConfig.weightUnit = c3925e.m25497h();
                    Keeper.keepPersonInfo(readPersonInfo);
                    Utils.m7998a(getActivity(), readPersonInfo);
                }
                a.m8790c(WeightUtil.m15698a(getActivity(), c3925e.m25497h()));
                // TBD DEBUG
//                Log.e(TAG, GuliLog.stackTracePrint() + c3925e.m25499j());
                a.m8773a(c3925e.m25499j());
                a.m8782b(WeightUtil.m15689a(c3925e.m25499j(), c3925e.m25497h()));
                a.m8792d(c3925e.m25498i());
                if (this.f9621G.f11135c == -1) {
                    age = Keeper.readPersonInfo().getAge();
                    i = Keeper.readPersonInfo().gender;
                } else {
                    UserInfo a2 = UserInfoManager.getInstance().getInfoByUid(this.f9621G.f11135c);
                    if (a2 != null) {
                        age = Birthday.fromStr(a2.birthday).getAge();
                        i = a2.gender;
                    } else {
                        age = 20;
                        i = f9611b;
                    }
                }
                a.m8804i(age);
                a.m8806j(i);
                a.m8794d(this.f9621G.f11134b);
                a.m8788c(this.f9621G.f11136d);
                if (this.f9621G.weightInfo.isStable()) {
                    a.m8800g(this.f9621G.f11135c);
                    Keeper.keepWeightCurrentUserAsync(this.f9621G.f11135c);
                }
                a.m8776a(this.f9621G);
                GuliLog.tracePrintInfo(TAG, "update UI " + this.f9621G.weightInfo.toString() + "  " + this.f9621G.f11135c + " " + this.f9621G.f11134b);
            }
            m14421a(a);
            GuliFragmentPagerAdapter aFVar = this.fragmentPagerAdapter;
            if (z) {
                z2 = false;
            }
            aFVar.m14261a(z2);
        }
    }

    private void m14435c(int i) {
        GuliLog.tracePrintInfo(TAG, "uid " + i);
        if (i == -1) {
            m14446h();
        }
        if (i == 0 || UserInfoManager.getInstance().getInfoByUid(i) == null) {
            m14437d((int) f9610a);
        } else {
            m14449i(i);
        }
    }

    private void m14437d(int i) {
        ScaleWeightInfo c3925e = this.f9621G.weightInfo;
        WeightInfo e = WeightInfoManager.getInstance().m15777e(i);
        float f = 0.0f;
        if (e != null) {
            f = e.weight;
            c3925e.setDate(e.timestamp);
            this.f9621G.f11137e = false;
        } else {
            this.f9621G.f11137e = true;
        }
        c3925e.m25488b(WeightUtil.m15706b(f, c3925e.m25497h()));
        c3925e.m25482a((float) -1.0f);
        this.f9621G.f11134b = getString(R.string.visitor);
        this.f9621G.f11136d = -1.0f;
        this.f9621G.f11135c = i;
        this.f9622H = this.f9621G;
    }

    private int m14438e(int i) {
        return m14428b(i, false);
    }

    private void m14441f(int i) {
        GuliLog.tracePrintInfo(TAG, "LastMode : " + this.type + " , ToMode : " + i);
        this.type = i;
        ChartData.m8731a().m8802h(this.type);
        ScaleActivity mainUIActivity = (ScaleActivity) getActivity();
        DynamicView f;
        switch (this.type) {
            case f9611b /*1*/:
                mainUIActivity.m13950c(this.type);
                mainUIActivity.m13952d((int) R.drawable.btn_statistic);
                C0668a.m8129a(getActivity(), C0668a.cH, ChartData.KEY_MODE, C0668a.cS);
                this.mTextView1.setVisibility(View.VISIBLE);
                this.mTextView1.setText(this.f9643w);
                f = this.fragmentPagerAdapter.m14266f(f9611b);
                if (f != null) {
                    f.m15133c(true);
                }
                break;
            case C4220a.bp /*16*/:
                mainUIActivity.m13950c(this.type);
                mainUIActivity.m13952d((int) R.drawable.btn_statistic);
                this.mTextView1.setVisibility(View.GONE);
                C0668a.m8129a(getActivity(), C0668a.cH, ChartData.KEY_MODE, C0668a.cT);
                break;
            case PersonInfo.INCOMING_CALL_DISABLE_BIT /*256*/:
                mainUIActivity.m13950c(this.type);
                mainUIActivity.m13952d((int) R.drawable.btn_statistic_weight);
                C0668a.m8129a(getActivity(), C0668a.cH, ChartData.KEY_MODE, C0668a.cU);
                this.mTextView1.setText(this.f9642v);
                if (DeviceSource.hasBindWeight()) {
                    this.mTextView1.setVisibility(View.INVISIBLE);
                } else {
                    this.mTextView1.setVisibility(View.VISIBLE);
                }
                f = this.fragmentPagerAdapter.m14266f(PersonInfo.INCOMING_CALL_DISABLE_BIT);
                if (f != null) {
                    f.m15130c().m8446b(0.0f);
                    f.m15125b((float) -1.0f);
                    f.m15133c(true);
                }
                break;
            default:
                break;
        }
    }

    private void m14442g(int i) {
        int h = m14444h(i);
        this.mViewPager.setBackgroundColor(h);
        ((ScaleActivity) getActivity()).applyStatusBarTint(h);
    }

    private int m14444h(int i) {
        GuliLog.tracePrintInfo(TAG, "Update Background Mode : " + i + ", HasBindDevices : " + DeviceSource.hasBindDevice());
        int i2 = this.f9640t;
        if (!DeviceSource.hasBindDevice(getActivity())) {
            return i2;
        }
        switch (i) {
            case f9611b /*1*/:
                return DeviceSource.hasBindStepDevice(getActivity()) ? this.f9638r : i2;
            case C4220a.bp /*16*/:
                return DeviceSource.hasBindBracelet() ? this.f9637q : i2;
            case PersonInfo.INCOMING_CALL_DISABLE_BIT /*256*/:
                return DeviceSource.hasBindWeight() ? this.f9639s : i2;
            default:
                return i2;
        }
    }

    private void m14446h() {
        ScaleWeightInfo c3925e = new ScaleWeightInfo();
        int i = Keeper.readPersonInfo().miliConfig.weightUnit;
        c3925e.setUnitType(i);
        c3925e.setStable(true);
        WeightInfo e = WeightInfoManager.getInstance().m15777e(-1);
        PersonInfo readPersonInfo = Keeper.readPersonInfo();
        float f = 0.0f;
        if (e != null) {
            GuliLog.tracePrintInfo(TAG, "Self latest info is not null " + e.toString());
            f = e.weight;
            c3925e.setDate(e.timestamp);
            this.f9621G.f11137e = false;
        } else {
            GuliLog.tracePrintInfo(TAG, "Self latest info is null ");
            this.f9621G.f11137e = true;
        }
        c3925e.m25488b(WeightUtil.m15706b(f, i));
        c3925e.m25482a(WeightUtil.m15693a(readPersonInfo.height, Birthday.fromStr(readPersonInfo.birthday).getAge(), f));
        this.f9621G.weightInfo = c3925e;
        this.f9621G.f11134b = readPersonInfo.nickname;
        this.f9621G.f11136d = readPersonInfo.targetWeight;
        this.f9621G.f11135c = -1;
        this.f9622H = this.f9621G;
    }

    private int m14447i() {
        return m14438e((int) f9611b);
    }

    private void m14449i(int i) {
        GuliLog.tracePrintInfo(TAG, "update latest user weight info " + i);
        UserInfo a = UserInfoManager.getInstance().getInfoByUid(i);
        if (a != null) {
            ScaleWeightInfo c3925e = this.f9621G.weightInfo;
            WeightInfo e = WeightInfoManager.getInstance().m15777e(i);
            float f = 0.0f;
            if (e != null) {
                GuliLog.tracePrintInfo(TAG, "weightAdvData " + this.f9621G.weightInfo.toString() + " timestampe " + this.f9621G.weightInfo.m25494e());
                GuliLog.tracePrintInfo(TAG, "latestInfo " + e.toString());
                f = e.weight;
                c3925e.setDate(e.timestamp);
                this.f9621G.f11137e = false;
            } else {
                this.f9621G.f11137e = true;
            }
            c3925e.m25488b(WeightUtil.m15706b(f, c3925e.m25497h()));
            c3925e.m25482a(WeightUtil.m15693a(a.height, Birthday.fromStr(a.birthday).getAge(), f));
            this.f9621G.f11134b = a.name;
            this.f9621G.f11136d = a.targetWeight;
            this.f9621G.f11135c = i;
            this.f9622H = this.f9621G;
        }
    }

    private void m14450j() {
        this.mAnimatorX = null;
        this.mAnimatorY = null;
        if (!DeviceSource.hasBindDevice(getActivity())) {
            return;
        }
        if (this.f9618D && this.f9619E && this.f9620F) {
            this.mAnimatorX = m14417a(m14444h(16), m14444h((int) f9611b));
            this.mAnimatorY = m14417a(m14444h((int) f9611b), m14444h((int) PersonInfo.INCOMING_CALL_DISABLE_BIT));
        } else if (this.f9618D && this.f9619E) {
            this.mAnimatorX = m14417a(m14444h(16), m14444h((int) f9611b));
        } else if (this.f9619E && this.f9620F) {
            this.mAnimatorX = m14417a(m14444h((int) f9611b), m14444h((int) PersonInfo.INCOMING_CALL_DISABLE_BIT));
        }
    }

    class aC extends Handler {
        final /* synthetic */ DynamicFragment f9472a;

        aC(DynamicFragment ayVar) {
            this.f9472a = ayVar;
        }

        public void handleMessage(Message message) {
            switch (message.what) {
                case 4114:
                    this.f9472a.m14458n();
                    GuliLog.tracePrintInfo("DDDD", "Dynamic Update : Data Loaded,Prev/Next Day,Animation");
                    this.f9472a.m14432b(false);
                    break;
                case 4115:
                    if (this.f9472a.f9631k != message.arg1) {
                        C0668a.m8126a(this.f9472a.getActivity(), C0668a.cQ);
                    }
                    this.f9472a.f9631k = message.arg1;
                    this.f9472a.m14432b(true);
                    break;
                case 4116:
                    C1981P c1981p = (C1981P) message.obj;
                    ScaleWeightInfo c3925e = c1981p.weightInfo;
                    if (c3925e.isStable() && !c3925e.isFinish()) {
                        this.f9472a.f9622H = c1981p;
                    }
                    if (c3925e.isFinish()) {
                        this.f9472a.f9621G = this.f9472a.f9622H;
                    } else {
                        this.f9472a.f9621G = c1981p;
                    }
                    if (this.f9472a.isAdded()) {
                        GuliLog.tracePrintInfo("DynamicFragment", "Dynamic Update : WeightAdvData receive:" + c1981p);
                        if (!(this.f9472a.type == PersonInfo.INCOMING_CALL_DISABLE_BIT || c3925e.isFinish())) {
                            this.f9472a.m14428b((int) PersonInfo.INCOMING_CALL_DISABLE_BIT, true);
                        }
                        if (c3925e.m25502m()) {
                            this.f9472a.m14454l();
                        } else if (c3925e.isFinish() && !c3925e.isStable() && c3925e.m25492c()) {
                            if (Utils.m8055c(this.f9472a.getActivity())) {
                                C3247b.m22929a(this.f9472a.getActivity(), (int) R.string.weighting_failed, 1, 17).show();
                            }
                        } else if (!c3925e.isFinish() && c3925e.isStable() && c1981p.f11135c == 0) {
                            List<UserInfo> list = c1981p.userInfoList;
                            if (list.size() == 0) {
                                GuliLog.tracePrintInfo("MATCHED_USERS", "userinfos size is 0");
                            } else if (list.size() == 1) {
                                GuliLog.tracePrintInfo("MATCHED_USERS", "match 1 user");
                            } else {
                                GuliLog.tracePrintInfo("MATCHED_USERS", "match more than 1 user ");
                                for (UserInfo userInfo : list) {
                                    GuliLog.tracePrintInfo("MATCHED_USERS", "info : " + userInfo.toString());
                                }
                            }
                            this.f9472a.m14426a(c3925e, (List) list);
                        }
                        this.f9472a.m14432b(true);
                    }
                    break;
                case 4117:
                    this.f9472a.m14420a(message);
                    break;
                default:
                    break;
            }
        }
    }

    private void m14452k() {
        mHandler = new aC(this);
    }

    static class an implements View.OnClickListener {
        final /* synthetic */ am f11349a;

        an(am amVar) {
            this.f11349a = amVar;
        }

        public void onClick(View view) {
            this.f11349a.dismiss();
        }
    }

    public static class am extends DimPanelFragment {
        protected int inflateLayout() {
            return R.layout.fragment_weight_overload;
        }

        public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
            View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
            ((TextView) onCreateView.findViewById(R.id.weight_overload_confirm_tv)).setOnClickListener(new an(this));
            return onCreateView;
        }
    }

    private void m14454l() {
        FragmentManager fragmentManager = getActivity().getFragmentManager();
        if (fragmentManager.findFragmentByTag(f9614e) == null) {
            new am().show(fragmentManager.beginTransaction(), f9614e);
        }
    }

    private void m14456m() {
        this.f9642v = getResources().getString(R.string.record_weight);
        this.f9643w = getResources().getString(R.string.go_running);
        if (this.type == f9611b) {
            this.mTextView1.setText(this.f9643w);
        } else if (this.type == PersonInfo.INCOMING_CALL_DISABLE_BIT) {
            this.mTextView1.setText(this.f9642v);
        }
    }

    private void m14458n() {
    }

    public void m14459a(float f) {
        if (getActivity() != null) {
            this.mTextView1.setTranslationY((((float) (-this.f9616B)) * (1.0f - f)) * 2.13f);
            this.fragmentPagerAdapter.m14259a(f);
        }
    }

    public void m10055a(int i) {
        GuliLog.tracePrintInfo("step", "process:" + i);
        if (i >= 0) {
            Keeper.keepRealtimeStepsTimestamp(System.currentTimeMillis(), this.f9623I);
            Keeper.keepRealtimeSteps(i, this.f9623I);
            if (DeviceSource.hasBindBracelet()) {
//                SwitchOperator readSwitchOperator = Keeper.readSwitchOperator();
//                if (readSwitchOperator.isValidBaseSteps()) {
//                    i += readSwitchOperator.steps;
//                }
            }
            Message message = new Message();
            message.arg1 = i;
            message.what = 4115;
            if (mHandler != null) {
                mHandler.sendMessage(message);
            }
        }
    }

    public void m14461a(int i, boolean z) {
        Message message = new Message();
        message.what = 4117;
        message.arg1 = i;
        message.arg2 = z ? f9611b : f9610a;
        mHandler.sendMessage(message);
    }

    public void m14462a(PageIndicator c1858c) {
        if (getActivity() != null) {
            this.fragmentPagerAdapter.m14260a(c1858c);
        }
    }

    public void m14463a(Boolean bool) {
        if (getActivity() != null) {
            this.fragmentPagerAdapter.m14263b(bool.booleanValue());
        }
    }

    public void m14464a(boolean z) {
        if (ChartData.m8731a().m8816t() != 0) {
            Message message = new Message();
            message.what = 4117;
            message.arg1 = ChartData.m8731a().m8816t();
            message.arg2 = z ? f9611b : f9610a;
            mHandler.sendMessage(message);
        }
    }

    public void m14465b() {
        if (this.mViewPager == null) {
            this.f9615A = Boolean.valueOf(true);
            return;
        }
        this.mViewPager.getHeight();
        this.mViewPager.getLayoutParams().height = (int) Utils.m8026b(372.0f, getActivity());
        this.mViewPager.requestLayout();
    }

    public void m14466b(int i) {
        m14442g(m14438e(i));
        m14441f(i);
        m14450j();
    }

    public TextView m14467c() {
        return this.mTextView1;
    }

    public void m14468d() {
        GuliLog.tracePrintInfo(TAG, "Has Bind Sensor-hub : " + DeviceSource.hasBindSensorHub() + ", Bind Weight : " + DeviceSource.hasBindWeight());
        this.f9618D = !DeviceSource.hasBindSensorHub();
        FragmentTransaction beginTransaction = this.mFragmentManager.beginTransaction();
        Iterator it = this.fragmentPagerAdapter.fragmentArrayList.iterator();
        while (it.hasNext()) {
            beginTransaction.remove((Fragment) it.next());
        }
        beginTransaction.commit();
        this.mFragmentManager.executePendingTransactions();
        this.fragmentPagerAdapter.m14264d();
//        this.fragmentPagerAdapter.m200c();
        this.mPageIndicator.notifyDataSetChanged();//m14947i();
        m14462a(this.mPageIndicator);
        ((View) this.mPageIndicator).setTranslationY(0.0f);
        m14469e();
    }

    public void m14469e() {
        // TBD HACK HERE
        // m14466b((int) f9611b);
        m14466b(256);
    }

    public C1981P m14470f() {
        return this.f9621G;
    }

    public C1981P m14471g() {
        return this.f9622H;
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        m14456m();
    }

    public void onCreate(Bundle bundle) {
        boolean z = false;
        super.onCreate(bundle);
        this.f9617C = false;
        m14452k();
        EventBus.getDefault().registerSticky(this);
        Resources resources = getActivity().getResources();
        this.f9637q = resources.getColor(R.color.bg_mode_sleep);
        this.f9638r = resources.getColor(R.color.bg_mode_step);
        this.f9639s = resources.getColor(R.color.bg_mode_weight);
        this.f9640t = resources.getColor(R.color.bg_mode_unbind);
        this.f9623I = this.mDataManager.m12239r();
        Point point = new Point();
        getActivity().getWindowManager().getDefaultDisplay().getSize(point);
        this.f9641u = point.x;
        GuliLog.tracePrintInfo(TAG, "Has Bind Sensor-hub : " + DeviceSource.hasBindSensorHub() + ", Bind Weight : " + DeviceSource.hasBindWeight() + ",mDeviceType = " + this.f9623I);
        if (!DeviceSource.hasBindSensorHub()) {
            z = true;
        }

        // turn off pages for sleep and step
        //this.f9618D = z;
        //this.f9619E = true;
        this.f9618D = false;
        this.f9619E = false;

        // TBD, here will go on to check if the scale is configured.
//        if (Config.m8876h().f4202l.f4259a.booleanValue()) {
            this.f9620F = true;
            this.f9621G.weightInfo.setUnitType(Keeper.readPersonInfo().miliConfig.weightUnit);
            this.f9621G.weightInfo.setStable(true); // m25486a
            m14435c(Keeper.readWeightCurrentUser(-1));
//        }
    }

    class ShortCutClickListener implements View.OnClickListener { // az
        final /* synthetic */ DynamicFragment dynamicFragment;

        ShortCutClickListener(DynamicFragment dynamicFragment) {
            this.dynamicFragment = dynamicFragment;
        }

        public void onClick(View view) {
            this.dynamicFragment.fragmentPagerAdapter.getPagerFragment(this.dynamicFragment.type).onShortCutAction();
        }
    }

    class aA implements ViewPager.OnPageChangeListener { // bz
        final /* synthetic */ DynamicFragment f9470a;

        aA(DynamicFragment ayVar) {
            this.f9470a = ayVar;
        }

        public void onPageSelected(int i) {  // m14251a
            if (this.f9470a.type != 0) {
                this.f9470a.m14441f(((PagerFragment) this.f9470a.fragmentPagerAdapter.getItem(i)).type);
            }
        }

        public void onPageScrolled(int i, float f, int i2) {
            int width = this.f9470a.mTextView1.getWidth();
            if (width != 0 && this.f9470a.f9641u - i2 < this.f9470a.f9641u / 2) {
                this.f9470a.mTextView1.setX((float) (((this.f9470a.f9641u * 2) - i2) - width));
            } else if (width != 0 && i2 < this.f9470a.f9641u / 2) {
                this.f9470a.mTextView1.setX((float) ((this.f9470a.f9641u - width) + i2));
            }
            if (this.f9470a.mAnimatorX == null || this.f9470a.mAnimatorY == null) {
                if (this.f9470a.mAnimatorX == null) {
                    return;
                }
                if (i == 0) {
                    AnimUtil.m8752a(this.f9470a.mAnimatorX, f);
                } else if (i == 1 && f == 0.0f) {
                    AnimUtil.m8752a(this.f9470a.mAnimatorX, 1.0f);
                }
            } else if (i == 0) {
                AnimUtil.m8752a(this.f9470a.mAnimatorX, f);
            } else if (i == 1) {
                AnimUtil.m8752a(this.f9470a.mAnimatorY, f);
            } else if (i == 2 && f == 0.0f) {
                AnimUtil.m8752a(this.f9470a.mAnimatorY, 1.0f);
            }
        }

        public void onPageScrollStateChanged (int i) { //m14253b
        }
    }

    @SuppressLint({"NewApi"})
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_dynamic, viewGroup, false);
        this.mViewPager = (ViewPager) inflate.findViewById(R.id.view_pager);
        this.mPageIndicator = (PageIndicator) inflate.findViewById(R.id.indicator);
        this.mTextView1 = (TextView) inflate.findViewById(R.id.shortcut);
        this.mTextView1.setOnClickListener(new ShortCutClickListener(this));
        this.f9616B = (int) Utils.m8026b(106.0f, getActivity());
        this.f9642v = getResources().getString(R.string.record_weight);
        this.f9643w = getResources().getString(R.string.go_running);
        if (Build.VERSION.SDK_INT < 17) {
            this.mFragmentManager = getFragmentManager();
        } else {
            this.mFragmentManager = getChildFragmentManager();
        }
        this.fragmentPagerAdapter = new GuliFragmentPagerAdapter(this, this.mFragmentManager);
        this.mViewPager.setAdapter(this.fragmentPagerAdapter); // m2469a //TBD
        this.mViewPager.setOffscreenPageLimit(3);
        this.mPageIndicator.setViewPager(this.mViewPager);
        this.mPageIndicator.setOnPageChangeListener(new aA(this));
        m14469e();
        if (this.f9615A.booleanValue()) {
            m14465b();
        }
        m14462a(this.mPageIndicator);
        if (C0804t.m8835a()) {
            ((CirclePageIndicator) this.mPageIndicator).setRadius(C0804t.m8825a(getActivity(), 2.3f));
        }
        return inflate;
    }

    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    public void onDetach() {
        super.onDetach();
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }
    }

    public void onEvent(EventGoalsUpdated eventGoalsUpdated) {
        GuliLog.tracePrintInfo(TAG, "onGoalsSettingChanged");
        if (isAdded()) {
            GuliLog.tracePrintInfo(TAG, "Dynamic Update : Goal Changed.");
            m14432b(true);
        }
    }

    public void onEvent(EventLoadDataComplete eventLoadDataComplete) {
        GuliLog.tracePrintInfo(TAG, "onLoadDataComplete");
        if (isAdded()) {
            GuliLog.tracePrintInfo(TAG, "Dynamic Update : Data Loaded,Animation");
            m14432b(false);
        }
    }

    public void onEvent(EventPersonInfoUpdateUnit eventPersonInfoUpdateUnit) {
        if (isAdded()) {
            this.fragmentPagerAdapter.m14261a(true);
        }
    }

//    public void onEvent(EventWeightLowBattery eventWeightLowBattery) {
//        GuliLog.m12370d(TAG, "Weight Scale Battery Low!!");
//        if (this.f9620F && !this.f9625K) {
//            mHandler.post(new aD(this));
//        }
//    }

    public void onEvent(EventWeightTargetUpdated eventWeightTargetUpdated) {
        GuliLog.tracePrintInfo(TAG, "onWeightTargetUpdated!!");
        if (isAdded()) {
            GuliLog.tracePrintInfo(TAG, "Dynamic Update : Weight Target Updated.");
            UserInfo a = UserInfoManager.getInstance().getInfoByUid(this.f9621G.f11135c);
            if (a != null) {
                this.f9621G.f11136d = a.targetWeight;
            }
            m14432b(true);
        }
    }

    public void onEvent(C1981P c1981p) {
        Message message = new Message();
        message.what = 4116;
        message.obj = c1981p;
        mHandler.sendMessage(message);
    }

    public void onEvent(HwConnStatus hwConnStatus) {
        GuliLog.tracePrintInfo(TAG, "onBleStatusChanged:" + hwConnStatus);
        if (hwConnStatus.m25408k()) {
//            RtStep.enableRtSteps(getActivity(), this.f9623I, !this.f9617C, this);
        }
    }

    public void onEvent(HwSyncDataStatus hwSyncDataStatus) {
        if (hwSyncDataStatus.m25417d() && isAdded()) {
            GuliLog.tracePrintInfo(TAG, "Dynamic Update : Data Synced.");
//            RtStep.enableRtSteps(getActivity(), this.f9623I, !this.f9617C, this);
            m14432b(true);
        }
    }

    public void onPause() {
        super.onPause();
        this.f9617C = true;
        C0668a.m8145d(getActivity(), C0668a.cH);
        C0668a.m8141b(C0668a.f3557a);
//        RtStep.enableRtSteps(getActivity(), this.f9623I, false, this);
    }

    public void onResume() {
        super.onResume();
        this.f9617C = false;
        this.f9623I = this.mDataManager.m12239r();
        if (this.f9624J != this.f9623I) {
            this.f9624J = this.f9623I;
            this.f9631k = Keeper.readRealtimeSteps(this.f9623I);
        }
        GuliLog.tracePrintInfo(TAG, "Dynamic Update : OnResume. mDeviceType = " + this.f9623I + ",mRtSteps= " + this.f9631k);
        m14432b(true);
//        RtStep.enableRtSteps(getActivity(), this.f9623I, true, this);
        C0668a.m8133a(C0668a.f3557a);
        C0668a.m8142c(getActivity(), C0668a.cH);
    }

    public void onStop() {
        super.onStop();
        GuliLog.tracePrintInfo(TAG, "onStop................");
        this.f9617C = true;
    }
}
